cc.Class({
    extends: cc.Component,

    properties: {
        
    },

    onLoad () {
        this.m = this.getComponent(cc.MeshRenderer);
        
        this.color = {
            r: 100,
            g: 0,
            b: 0
        };
        
        cc.tween(this.color)
            .repeatForever(
                cc.tween()
                .to(0.8, {r: 255, g: 0, b: 0})
                .to(0.8, {r: 0, g: 100, b: 0})
                .to(0.8, {r: 0, g: 255, b: 0})
                .to(0.8, {r: 0, g: 0, b: 100})
                .to(0.8, {r: 0, g: 0, b: 255})
                .to(0.8, {r: 100, g: 0, b: 0})
            )
            .start();
    },

    setColor () {
        let color = cc.color(this.color.r, this.color.g, this.color.b, 255);
        this.m.sharedMaterials[0].setProperty('diffuseColor', color);
    },

    update (dt) {
        this.setColor();
    }

});
